import { KujialeParamModel } from "../types/KujialeJsonModels/KujialeParamModel";
import { Mesh, BoxGeometry, MeshBasicMaterial } from "three";
import { Box3DMesh } from "../types/DrawingGroups/meshs";
import { BoxModel } from "../types/Models";
import { type DrawContext } from "./context";
import { DrawMeshWireframeLines } from "./wireframe";

export const Draw3DBoxMesh = (
    json: KujialeParamModel,
    context: DrawContext
  ): Mesh | undefined => {
    const geometry = new BoxGeometry(
      json.size!["x"],
      json.size!["z"],
      json.size!["y"]
    );
    const material = new MeshBasicMaterial({
      color: json.textureName in context.colors ? context.colors[json.textureName] :context.colors['error'],
    });
    const mesh = new Box3DMesh(new BoxModel(json));
    mesh.geometry = geometry;
    mesh.material = material;
  
    mesh.rotateAndMoveByModel();
    DrawMeshWireframeLines(mesh, true, context.colors['wireframe']);
    return mesh;
  };
  